package Application.UIEditApplication.view.ui.cell
{
	import fl.containers.UILoader;
	
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.GlowFilter;
	import flash.geom.Rectangle;
	import flash.net.URLRequest;
	
	import XComponent.hide.XEvent;

	public class ComponentListCell		extends BaseCell
	{
		private var m_uiImg : UILoader;
	
		
		public function ComponentListCell()
		{
			m_uiImg = new UILoader;
			
			this.buttonMode = true;
			
			this.mouseChildren = false;
			
			this.addChild(m_uiImg);
			
			this.addEventListener(MouseEvent.CLICK,OnClick,false,0,true);
		}
		
		public function  OnClick(evt : MouseEvent) : void
		{
			if(this.listData)
			{
				this.listData.owner.dispatchEvent(new XEvent(XEvent.XEVENT_SELECT,data));
			}
		}
		
		override public function set data(value:Object):void
		{
			super.data = value;
			
			if(data)
			{
				m_uiImg.load(new URLRequest(data["imgURL"]));
				
				m_uiImg.addEventListener(Event.COMPLETE,loadComplete);
			}
		}
		
		override public function set selected(arg:Boolean):void
		{
			super.selected = arg;
			

			if(arg)
			{
				this.filters = [new GlowFilter(0xCC3300,1,6,6,5,1,true)];
			}
			else
			{
				this.filters = [];	
			}
		}
		
		private function loadComplete(evt : Event) : void
		{
			m_uiImg.removeEventListener(Event.COMPLETE,loadComplete);
			
			m_uiImg.width = 	m_uiImg.content.width;
			m_uiImg.height = 	m_uiImg.content.height;
	
		}
	}
}